package com.ym.controller.financialManagement;

import com.github.pagehelper.PageInfo;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.utils.excel.ExportExcelUtil;
import com.ym.medical.domain.param.TdRecordExampleParam;
import com.ym.medical.domain.vo.InquiryTdRecordVO;
import com.ym.medical.domain.vo.PerTransfTdRecordVO;
import com.ym.medical.domain.vo.ToMindTdRecordVO;
import com.ym.medical.service.IInquiryOrderSV;
import com.ym.medical.service.IMindSV;
import com.ym.medical.service.IPersonalTransactionOrderSV;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "订单交易管理")
@RestController
@RequestMapping("/management/orderTd")
@Validated
public class OrderTdManagement extends BaseController {

	@Autowired
	private IInquiryOrderSV inquiryOrderSV;

	@Autowired
	private IMindSV mindSV;

	@Autowired
	private IPersonalTransactionOrderSV personalTransactionOrderSV;

	@ApiOperation("问诊交易记录展示")
	@GetMapping(value = "/inquiryRecord/list")
	public APIResponse<PageInfo<InquiryTdRecordVO>> listInquiryOrder(
			TdRecordExampleParam tdRecordExampleParam,
			@RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int limit
	) {
		return successData(inquiryOrderSV.listInquiryOrderRecord(tdRecordExampleParam, pageNo, limit));
	}

	@ApiOperation("送心意记录展示")
	@GetMapping(value = "/toMindRecord/list")
	public APIResponse<PageInfo<ToMindTdRecordVO>> listMindRecord(
			TdRecordExampleParam tdRecordExampleParam,
			@RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int limit
	) {
		return successData(mindSV.listMindRecord(tdRecordExampleParam, pageNo, limit));
	}

	@ApiOperation("个人交易订单展示")
	@GetMapping(value = "/personalTransaction/list")
	public APIResponse<PageInfo<PerTransfTdRecordVO>> listPersonalTransaction(
			TdRecordExampleParam tdRecordExampleParam,
			@RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int limit
	) {
		return successData(personalTransactionOrderSV.listPersonalTransaction(tdRecordExampleParam, pageNo, limit));
	}

	@ApiOperation("送心意记录导出")
	@PostMapping("/exportToMindRecord")
	public void exportToMindRecord(HttpServletResponse response,
                                   @RequestBody TdRecordExampleParam tdRecordExampleVO,
                                   @RequestParam(defaultValue = "1") int pageNo,
                                   @RequestParam(defaultValue = "10") int limit) throws Exception {
		ExportExcelUtil exportExcelUtil = new ExportExcelUtil();
		String titleName = "送心意记录";
		String[] headerString = {"订单编号", "患者姓名", "医生姓名", "答谢来源", "答谢金额", "支付状态", "付款方式", "付款账户", "交易时间", "创建时间"};
		String[] headerField = {"ioNum", "patientName", "docRealName", "thankSorceName", "thankMoney", "thankPayStateName", "thankPayWayName", "payAcc", "tdTime", "createTime"};

		PageInfo<ToMindTdRecordVO> toMindTdRecordVOPageInfo = mindSV.listMindRecord(tdRecordExampleVO, pageNo, limit);
		List<ToMindTdRecordVO> list = toMindTdRecordVOPageInfo.getList();
		exportExcelUtil.exportExcelForTotal(titleName, headerString, headerField, null, list, response, null);
	}

	@ApiOperation("个人交易订单记录导出")
	@PostMapping("/exportPersonalTransaction")
	public void exportPersonalTransaction(HttpServletResponse response,
                                          @RequestBody TdRecordExampleParam tdRecordExampleParam,
                                          @RequestParam(defaultValue = "1") int pageNo,
                                          @RequestParam(defaultValue = "10") int limit) throws Exception {
		ExportExcelUtil exportExcelUtil = new ExportExcelUtil();
		String titleName = "个人交易订单记录";
		String[] headerString = {"订单编号", "患者姓名", "订单类型", "交易状态", "支付状态", "交易金额", "付款方式", "付款账户", "交易时间", "创建时间"};
		String[] headerField = {"ioNum", "patientName", "ioTypeName", "tdStateName", "ioPayMentStateName", "tdAmount", "dfAccTypeName", "dfAcc", "tdTime", "createTime"};

		List<PerTransfTdRecordVO> perTransfTdRecordVOList = personalTransactionOrderSV.listPersonalTransaction(tdRecordExampleParam, pageNo, limit).getList();
		exportExcelUtil.exportExcelForTotal(titleName, headerString, headerField, null, perTransfTdRecordVOList, response, null);
	}

	@ApiOperation("问诊交易记录导出")
	@PostMapping(value = "/exportInquiryRecord")
	public void exportInquiryRecord(
			HttpServletResponse response,
			@RequestBody TdRecordExampleParam tdRecordExampleParam,
			@RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "1000000") int limit
	) throws Exception {
		List<InquiryTdRecordVO> inquiryOrderRecord = inquiryOrderSV.listInquiryOrderRecord(tdRecordExampleParam, pageNo, limit).getList();
		ExportExcelUtil exportExcelUtil = new ExportExcelUtil();
		String titleName = "问诊交易记录";
		String[] firstHeader = {"专家", "医生", "患者"};
		String[] secondHeader = {"订单编号", "医院", "科室", "姓名", "交易单号", "所得金额", "交易后账户余额",
				"姓名", "交易单号", "所得金额","交易后账户余额",
				"姓名","手机号","证件号码","交易单号","交易后账户余额","订单状态","支付状态","交易金额"};
		String[] headerField = {"ioNum", "hostHosName", "hostDeptName", "hostRealName", "hostTdNo", "hostTdAmount", "hostAftTdAmount",
				"docRealName", "docTdNo", "docTdAmount","docAftTdAmount",
				"patientName","patientPhoneNo","patientNo","patientTdNo","patientAftTdAmount","ioStateName","ioPaymentStateName","ioPaymentPrice",};

		exportExcelUtil.exportSubTitleExcelForTotal(titleName, firstHeader,secondHeader, headerField, null, inquiryOrderRecord, response, null);
	}
}
